package com.lrkj.payfee.controller;

import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.payfee.domain.CopyRoom;
import com.lrkj.payfee.service.ICopyRoomService;
import com.lrkj.payfee.vo.CopyRoomVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 抄房间仪表Controller
 *
 * @author yajun_ren
 * @date 2021-07-30
 */
@RestController
@RequestMapping("/payfee/copyroom")
public class CopyRoomController extends BaseController {
    @Autowired
    private ICopyRoomService copyRoomService;

    /**
     * 查询抄房间仪表列表
     */
    @ApiOperation(value = "查询抄房间仪表列表", notes = "查询抄房间仪表列表")
    @GetMapping("/list")
    public TableDataInfo list(CopyRoom copyRoom) {
        startPage();
        this.changeParameter(copyRoom.getParams());
        List<CopyRoom> list = copyRoomService.selectCopyRoomList(copyRoom);
        return getDataTable(list);
    }

    /**
     * 导出抄房间仪表列表
     */
    @ApiOperation(value = "导出抄房间仪表列表", notes = "导出抄房间仪表列表")
    @PreAuthorize("@ss.hasPermi('payfee:copyroom:export')")
    @Log(title = "抄房间仪表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CopyRoom copyRoom) {
        List<CopyRoom> list = copyRoomService.selectCopyRoomList(copyRoom);
        ExcelUtil<CopyRoom> util = new ExcelUtil<CopyRoom>(CopyRoom.class);
        return util.exportExcel(list, "抄房间仪表数据");
    }

    /**
     * 获取抄房间仪表详细信息
     */
    @ApiOperation(value = "获取抄房间仪表详细信息", notes = "获取抄房间仪表详细信息")
    @PreAuthorize("@ss.hasPermi('payfee:copyroom:query')")
    @GetMapping(value = "/{copyId}")
    public AjaxResult getInfo(@PathVariable("copyId") String copyId) {
        return AjaxResult.success(copyRoomService.selectCopyRoomById(copyId));
    }

    /**
     * 新增抄房间仪表
     */
    @ApiOperation(value = "新增抄房间仪表", notes = "新增抄房间仪表")
    @PreAuthorize("@ss.hasPermi('payfee:copyroom:add')")
    @Log(title = "抄房间仪表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CopyRoom copyRoom) {
        return toAjax(copyRoomService.insertCopyRoom(copyRoom));
    }

    /**
     * 修改抄房间仪表
     */
    @ApiOperation(value = "修改抄房间仪表", notes = "修改抄房间仪表")
    @PreAuthorize("@ss.hasPermi('payfee:copyroom:edit')")
    @Log(title = "抄房间仪表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CopyRoom copyRoom) {
        return toAjax(copyRoomService.updateCopyRoom(copyRoom));
    }

    /**
     * 删除抄房间仪表
     */
    @ApiOperation(value = "删除抄房间仪表", notes = "删除抄房间仪表")
    @PreAuthorize("@ss.hasPermi('payfee:copyroom:remove')")
    @Log(title = "抄房间仪表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{copyIds}")
    public AjaxResult remove(@PathVariable String[] copyIds) {
        return toAjax(copyRoomService.deleteCopyRoomByIds(copyIds));
    }


    /**
     * 获取房间仪表上一次读数
     *
     * @param rometerId 房间仪表ID
     */
    @ApiOperation(value = "获取房间仪表上一次读数", notes = "获取房间仪表上一次读数")
    @GetMapping(value = "/lastRoomReading/{rometerId}")
    public AjaxResult lastRoomReading(@PathVariable("rometerId") String rometerId) {
        return AjaxResult.success(copyRoomService.lastRoomReading(rometerId));
    }

    /**
     * 批量生成房间仪表费用
     */
    @ApiOperation(value = "批量生成房间仪表费用", notes = "批量生成房间仪表费用")
    @Log(title = "抄房间仪表", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('payfee:copyroom:batchPayfee')")
    @PostMapping("/batchPayfee")
    public AjaxResult batchPayfee(@RequestBody CopyRoomVo copyRoomVo) {
        return AjaxResult.success(copyRoomService.batchPayfee(copyRoomVo));
    }


}
